package net.lb.io.json.serializer;

import java.lang.reflect.Type;
import java.util.Date;
import net.lb.baseutil.collection.ObjectCollect;
import net.lb.baseutil.collection.StringCache;
import net.lb.io.json.field.JsonField;
import net.lb.io.json.util.JsonSerializer;

public class DateToLongSerializer implements JsonSerializer
{
    
    @Override
    public Object transToJsonvalue(Object src, ObjectCollect collect)
    {
        Date date = (Date) src;
        return date.getTime();
    }
    
    @Override
    public void setJsonFields(JsonField[] jsonFields)
    {
        // TODO Auto-generated method stub
        
    }
    
    @Override
    public void writeToString(StringCache cache, Object value, ObjectCollect collect)
    {
        Date date = (Date) value;
        cache.append(date.getTime());
    }
    
    @Override
    public Object toBean(Object value, Type type)
    {
        Date date = new Date((Long) value);
        return date;
    }
    
}
